package com.gexin.controller.system;

import java.util.HashMap;
import java.util.Map;
import com.gexin.common.WebConst;
import com.gexin.common.model.ApiResponse;
import com.gexin.common.utils.WindowsInfoUtil;
import com.gexin.core.web.SystemBaseController;
import com.gexin.model.system.AdminRes;
import com.gexin.model.system.AdminUser;
import com.gexin.model.system.RoleKit;
import com.gexin.plugin.sqlinxml.SqlKit;
import com.jfinal.ext.route.ControllerBind;
import com.jfinal.kit.PathKit;
import com.jfinal.plugin.activerecord.Db;

@ControllerBind(controllerKey = "/system", viewPath = "WEB-INF/system/")
public class AdminIndexController extends SystemBaseController {

	// 进框架页
	public void index() {
		AdminUser   user =  getLogintUser();
		if(user.getRoleId()==-1){
			getRequest().setAttribute(WebConst.Session_SysUserRoleMenu, AdminRes.dao.adminRole());//如果是系统管理员就加载全部
		}else{
			getRequest().setAttribute(WebConst.Session_SysUserRoleMenu, RoleKit.getRoleResByUserId(user.getId()));//去读取缓存菜单
		}
		String go = getPara("go",null);
		if (("/system/index").equals(go)) {
			go = null;
		}
		setAttr("go_url", go);	
		render("index.html");
	}

	// 跳首页
	public void console() {
		Map<String,String> map  =new HashMap<String,String>();
		map.put("os_name", System.getProperty("os.name"));//系统版本
		map.put("app_path", PathKit.getWebRootPath());//网站部署路径
		map.put("java_version",System.getProperty("java.version"));
		map.put("java_model",System.getProperty("sun.arch.data.model"));//JDK多少位的
		setAttr("os",map);
		setAttr("record", Db.findFirst(SqlKit.sql("admin.getDataSum")));
		render("console.html");
	}
	
	@Deprecated
	public void readCpuAndMemery() {
		Map<String,String> map  =new HashMap<String,String>();
		map.put("cpu", WindowsInfoUtil.getCpuRatioForWindows());
		map.put("memery", WindowsInfoUtil.getMemery());
		renderJson(new ApiResponse(map));
	}

}
